#include <stdio.h>
#include <stdlib.h>

#include <ldap.h>

int main( void )
{
	LDAP *ld;
	char uri[] = "ldap://192.168.1.90/"; 
	int result;
	int fd = -1;
	int asyncOption = LDAP_OPT_ON;
	
	
	result = ldap_initialize( &ld, uri );
	if( result == LDAP_SUCCESS )
	{
		printf( "Initialized connection OK\n" );
	}
	else
	{
		printf( ":( connection didn't init...\n" );
	}
	
	result = ldap_set_option( NULL, LDAP_OPT_CONNECT_ASYNC, LDAP_OPT_ON );
	if( result == LDAP_SUCCESS )
	{
		int opt;
		ldap_get_option( NULL, LDAP_OPT_CONNECT_ASYNC, &opt );
		
		printf( "Async connect mode set, value %i\n", opt );
	}

	
	result = ldap_simple_bind( ld, "anonymous", "" );
	if( result == LDAP_SUCCESS )
	{
		printf( "Initialized connection OK\n" );
	}
	else
	{
		int ld_errno;
		ldap_get_option( ld, LDAP_OPT_RESULT_CODE, &ld_errno );
		printf( "Sorry, %s \n", ldap_err2string( ld_errno ) );
	}
	
	
	// See if we can get a valid FD at this point
	ldap_get_option( ld, LDAP_OPT_DESC, &fd );
	printf( "Got FD %i\n",  fd);
	
	return 0;
}
